var member;
var currPage=1;
var pageSize=8;
var queryStatus=GetQueryString("queryStatus");
var memberId;
var count=0;
var GG = {
    "kk":function(mm){
       // alert(mm);
    }
}
$(function(){
	if(!queryStatus){
		queryStatus=1;
	}
	member=getEntity("memberInfo");
	init(member.mId,queryStatus,pageSize,currPage)
	//点击下一页事件
	$("#page").click(function(){
		currPage=$(".pageItemActive").attr("page-data");
		init(member.mId,queryStatus,pageSize,currPage);
	});
})
function delCollection(id){
	$.ajax({
		type:'post',
		url:rootPath+'/favorites/deleteFavorites',
		data:{'fids':id},
		//dataType:"json",
		success:function(data){
			location.reload(true);
		}
	})
}


function init(memberId,queryStatus,pageSize,currPage){
	$.ajax({
		type:"post",
		url:rootPath+"/favorites/selectByPage",
		data:{'mId':member.mId,'collectionType':queryStatus,'currPage':currPage,'pageSize':pageSize},
		dataType:"JSON",
		success:function(data){
			$("#collections").empty();
			count=data.count;
			var str='';
			var collections=data.data;
			$.each(collections,function(i,item){
				str+=createHtml(item,i);
			});
			$("#collections").append(str);
			$(".page").initPage(count,currPage,GG.kk);
		}	
	});
}
function createHtml(item,i){
	var str='';
	if((i+1)%4==0&&i>0){
		str+='<li class="last"><a href="'+rootPath+'/goods/queryGoodsDetail?id='+item.goodsId+'"><img src="'+item.img+'" alt="" /></a>'
	}else{
		str+='<li><a href="'+rootPath+'/goods/queryGoodsDetail?id='+item.goodsId+'"><img src="'+item.img+'" alt="" /></a>'
	}
	str+='<p class="price">￥'+item.marketPrice+'</p>'
		+'<a href="'+rootPath+'/goods/queryGoodsDetail?id='+item.goodsId+'"><p>'+item.name+'</p></a>'
		+'<img src="'+rootPath+'/images/col_del.png" alt="" class="del" onclick="delCollection(\''+item.id+'\')"/></li>'
	return str;
}

function tt(dd){
    //alert(dd);
}

